package com.fs.system.college_admin.controller;

import com.fs.system.college_admin.domain.Classes;
import com.fs.system.college_admin.service.CollgeAdminClassesService;
import com.fs.system.common.ResponseData;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/collegeAdminClasses")
public class CollegeAdminClassesController {
    @Autowired
    private CollgeAdminClassesService collgeAdminClassesService;

    /**
     * 获取班级信息
     * @param classes 查询条件
     * @param collegeId 学院ID
     * @return 响应数据
     */
    @GetMapping("/getClasses")
    public ResponseData getClasses(Classes classes, @RequestParam Long collegeId) {
        System.out.println("----------------collegeId:"+collegeId);
        System.out.println("----------------classes:"+classes);
        List<Classes> dbclasses = collgeAdminClassesService.getClassesByCollege(classes, collegeId);
        return new ResponseData("200", "查询成功", dbclasses);
    }

    /**
     * 分页查询班级信息
     * @param pageNum 页码
     * @param pageSize 每页数量
     * @param classes 查询条件
     * @param collegeId 学院ID
     * @return 响应数据
     */
    @GetMapping("/selectPage")
    public ResponseData selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                   @RequestParam(defaultValue = "5") Integer pageSize,
                                   Classes classes,
                                   @RequestParam Long collegeId) {
        System.out.println("specialityId:"+classes.getSpecialityId());
        System.out.println("-----------pageNum:"+pageNum);
        System.out.println("-----------pageSize:"+pageSize);
        System.out.println("-----------classes:"+classes);
        System.out.println("-----------collegeId:"+collegeId);
        PageInfo<Classes> classesPageInfo = collgeAdminClassesService.selectPage(pageNum, pageSize, classes, collegeId);
        System.out.println("------------"+classesPageInfo);
        return new ResponseData("200", "查询成功", classesPageInfo);
    }

    /**
     * 添加班级信息
     * @param classes 班级对象
     * @param collegeId 学院ID
     * @return 响应数据
     */
    @PostMapping("/addOneClasses")
    public ResponseData addOneClasses(@RequestBody Classes classes, @RequestParam Long collegeId) {
        collgeAdminClassesService.addOneClasses(classes, collegeId);
        return new ResponseData("200", "添加成功");
    }

    /**
     * 修改班级信息
     * @param classes 班级对象
     * @return 响应数据
     */
    @PutMapping("/updateClasses")
    public ResponseData updateClasses(@RequestBody Classes classes) {
        collgeAdminClassesService.updateClasses(classes);
        return new ResponseData("200", "修改成功");
    }

    /**
     * 删除班级信息
     * @param classId 班级id
     * @param updateBy 修改人
     * @return 响应数据
     */
    @PutMapping("/deleteClasses/{classId}")
    public ResponseData deleteClasses(@PathVariable Long classId, @RequestParam String updateBy) {
        collgeAdminClassesService.deleteClasses(classId,updateBy);
        return new ResponseData("200", "删除成功");
    }

    /**
     * 批量删除班级信息
     * @param ids 批量删除的班级id
     * @param updateBy 修改人
     * @return 响应数据
     */
    @PutMapping("/deleteBatch/{updateBy}")
    public ResponseData deleteBatch(@PathVariable String updateBy, @RequestBody List<Long> ids) {
        collgeAdminClassesService.deleteBatch(updateBy,ids);
        return new ResponseData("200", "批量删除成功");
    }

}